<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>详情</title>
</head>
<body>
<h1>微博详情页面</h1>
<div>
    <h2>
        {{weibo.nickname}}说:{{weibo.content}}
    </h2>
    <img :src="weibo.url" width="200" alt="">
    <hr>
    <h1>评论相关</h1>
    <div v-for="c in arr">
        <h3>{{c.nickname}}评论说{{c.content}}</h3>
    </div>
    <input type="text" placeholder="评论内容..." v-model="comment.content">
    <input type="button" value="评论" @click="comment()">
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
 <script>
  let v = new Vue({
     el:"body>div",
     data:{
         weibo:{},
         comment:{
             content:"",
             weiboId:""
         },
         arr:[]
     },
     methods:{
         send(){
             //把进入页面请求到微博对象里面的id取出赋值给评论对象
             v.comment.weiboId=v.weibo.id;
             axios.post("/comment/insert",v.comment).then(function (response) {
                if(response.data==1) {
                    alert("评论完成!");
                    location.reload();
                }else{
                    alert("请先登录")
                    location.href = "/log.html";
                }
             })
         }
     },
      created:function () {
         //通过地址栏中的id获取微博详情
         axios.get("/weibo/selectById"+location.search).then(function (response) {
             v.weibo=response.data;
         })
        //通过weiboId发请求获取相关评论信息
          axios.get("/comment/selectByWeiboId"+location.search).then(function (response) {
              v.arr=response.data;
          })
      }
   })
   </script>
</body>
</html>